﻿//-----------------------------------------------------------------------
// <copyright file="OutcomeButtons.cs">(c) http://TfsBuildExtensions.codeplex.com/. All other rights reserved.</copyright>
//-----------------------------------------------------------------------
namespace TfsBuildExtensions.Activities.TeamFoundationServer
{
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using DocumentFormat.OpenXml.Packaging;

    /// <summary>
    /// Traffic lights for showing the outcome of the testcase result
    /// </summary>
    internal enum ButtonType
    {
        Green,
        Yellow,
        Red
    }

    /// <summary>
    /// Feeds the button bitmaps to word
    /// </summary>
    internal static class OutcomeButtons
    {
        const string greenButton = "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA65JREFUeNrslW9MU2cUxp97Ke29t73kFri1YCcdoIKKToobE22XuWHJlmm2fZgwY7JskcwPOmayxcQssg+LI5LJmOLmxqI1c0ScyqTTsmjiJpWCS2FAhvYO2l4tBRURYgm9fTe3gMs2/4DbN0/yfjonz3nf5+T8XooQgv8zqIcNJkK3m8rTXxZ3gIsWB969Kk8mbjV40MN+BsvC8izFLZ0ly7c/7mVKkTqR+y/E8xa8P1s51dVENh/cSL5tP0rYtXSH+uU/mzyQOLcHufO2ZUS/73aRt+o2kGeqCgj3torscH1A+FWMV22HQE/Xc+0uymLuT/d8vGZ33LGeerSPnsfZGz8ilhqFs7cBPC3EKeN/G/KMg4xwsyf2IZNJ14SLI+fvJM7VUJa0QXNL9as1dINUj87hDpwbdCNeqwIfEhBtjvfFMGa7VHdFvu3lHvCJFZrTnpCbZO8yB7laLPo3W4T9yMve/qjSFHSSTe71pMhlJcY6lpgbBZK+00DUz9IXmKLbQ/7jBWKlhtdF9d/Urtm/gokymCWmI29vjv+mOPT8tZJYx8TNUw5xuWLA5NlZ/AntvHwM0ugFtN/4CayWwXgXwcXDskTTMVvESYKTe8BsRcJineVo2aqyp5I0IvrHQqBoCgWpVhTsyw1GZ0S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Ern9TPStuN7SB/REWyh527vRYtAs3vHI09nEvpx+XrlyEViuC+SShETmjdhLrB4UBWVMiyQbl36LybEGsXzi9G3UMoIpDPyM9SB2UcVb5DAe8PiY+GFOr5kgXuZ9HQiTVAa5FyF+4jB6TmqyeBr5foKYo61uf3M4GC4OTGa7ZULIxxDITx4dYubkuJdin52VGRDcKFSn6ZQQ+YdBEJ03+cCGjdmL1tMt85qcHmKlBebsvntBkrZcB1EDQFnns0evq9z60sGf7QIgjGjH7epeF6YRWGyaB6CiTBwV0Psm3RO2CNnDUhBUwIziHqFWrPEi29CpwNh/6p2DUFokaD6LrYN7gHvXE+4hO0Xvr5HhaNR+VTjuUqJMyfn9a3hmgPrufn2KXGkSTaFB6IFrIn4ElMyE4TokuHMRxBiLgl0DxWhFT/8qr32S9Vscru92fL3wIMABMdlsktT/5AAAAAAElFTkSuQmCC";

        // Generates content of part.
        internal static void FeedContentToImagePart(ImagePart part, ButtonType buttonType)
        {
            switch (buttonType)
            {
                case ButtonType.Green:
                    using (var data = GetBinaryDataStream(greenButton))
                    {
                        part.FeedData(data);
                    }
                    break;
                case ButtonType.Yellow:
                    using (var data = GetBinaryDataStream(yellowButton))
                    {
                        part.FeedData(data);
                    }
                    break;
                case ButtonType.Red:
                    using (var data = GetBinaryDataStream(redButton))
                    {
                        part.FeedData(data);
                    }
                    break;
            }
        }

        static Stream GetBinaryDataStream(string base64String)
        {
            return new MemoryStream(System.Convert.FromBase64String(base64String));
        }
    }
}
